package com.xiong.excel.utils;

import java.math.BigDecimal;
import java.math.RoundingMode;

/**
 * <p>
 *
 * @author XiongDa
 * @version 1.0.0
 * @belongsProject: excel-process
 * @belongsPackage: com.xiong.excel.utils
 * @since 2023/4/12 16:12
 **/
public class BigDecimalCount {

    public static Double BigDecimalCal(Double d1,String operation,Double d2){
        BigDecimal bd = new BigDecimal("0");
        if(d1!=null && d2!=null){
            if("+".equals(operation)){
                bd = new BigDecimal(String.valueOf(d1)).add(new BigDecimal(String.valueOf(d2)));
            }else if("-".equals(operation)){
                bd = new BigDecimal(String.valueOf(d1)).subtract(new BigDecimal(String.valueOf(d2)));
            }else if("*".equals(operation)){
                bd = new BigDecimal(String.valueOf(d1)).multiply(new BigDecimal(String.valueOf(d2)));
            }else if("/".equals(operation)){
                bd = new BigDecimal(String.valueOf(d1)).divide(new BigDecimal(String.valueOf(d2)),6, RoundingMode.HALF_UP);
            }
        }
        return bd.doubleValue();
    }

    public static String BigDecimalCal(String d1,String operation,String d2){
        BigDecimal bd = new BigDecimal("0");
        if(d1!=null && d2!=null){
            if("+".equals(operation)){
                bd = new BigDecimal(d1).add(new BigDecimal(d2));
            }else if("-".equals(operation)){
                bd = new BigDecimal(d1).subtract(new BigDecimal(d2));
            }else if("*".equals(operation)){
                bd = new BigDecimal(d1).multiply(new BigDecimal(d2));
            }else if("/".equals(operation)){
                bd = new BigDecimal(d1).divide(new BigDecimal(d2),6,RoundingMode.HALF_UP);
            }
        }
        return bd.toString();
    }

}
